<?php
namespace backend\models\activeRecords;

use common\models\User;
use Yii;
use yii\db\ActiveRecord;

/**
 * This is the model class for table "{{%guild}}".
 *
 * @property string $id 自增id
 * @property string $guild_name 公会名称
 * @property string $guild_sign 公会标识(推荐拼音缩写)
 * @property string $guild_contact 公会联系人
 * @property string $guild_phone 手机号
 * @property string $guild_qq QQ
 * @property int $guild_status 状态
 * @property int $guild_bank 银行信息
 * @property int $guild_game 游戏信息
 * @property string $guild_divide 分成比例
 * @property string $guild_deducted 扣量比例
 * @property int $add_time 添加时间
 * @property int $user_id 管理员ID
 */
class Guild extends ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%guild}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['guild_name', 'guild_sign', 'guild_contact', 'guild_phone'], 'required'],
            [['guild_status', 'guild_bank', 'guild_game', 'add_time'], 'integer'],
            [['guild_divide', 'guild_deducted','user_id'], 'number'],
            [['guild_name', 'guild_sign'], 'string', 'max' => 255],
            [['guild_contact'], 'string', 'max' => 32],
            [['guild_phone'], 'string', 'max' => 15],
            [['guild_qq'], 'string', 'max' => 20],
            [['guild_name'], 'unique'],
            [['guild_sign'], 'unique'],
            [['user_id'], 'unique'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app', '自增id'),
            'guild_name' => Yii::t('app', '公会名称'),
            'guild_sign' => Yii::t('app', '公会标识(推荐拼音缩写)'),
            'guild_contact' => Yii::t('app', '公会联系人'),
            'guild_phone' => Yii::t('app', '手机号'),
            'guild_qq' => Yii::t('app', 'QQ'),
            'guild_status' => Yii::t('app', '状态'),
            'guild_bank' => Yii::t('app', '银行信息'),
            'guild_game' => Yii::t('app', '游戏信息'),
            'guild_divide' => Yii::t('app', '分成比例'),
            'guild_deducted' => Yii::t('app', '扣量比例'),
            'add_time' => Yii::t('app', '添加时间'),
            'user_id' => Yii::t('app', '公会管理员ID'),
        ];
    }

    public static function getSpreadMember()
    {
        $userList = User::find()
            ->where('parent = :parent',[':parent'=>Yii::$app->user->getIdentity()->parent])
            ->all();
        $list = [];
        foreach($userList as $value){
            $list[$value->position] = $value->username;
        }
        return $list;
    }


}
